<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/core" prefix="c"%>
<script type="text/javascript">
 function validate(){
                	
        var customerDescription = document.getElementById('instructionPurchaseForecastSearchView.customerDescription').value;
        var itemDescription = document.getElementById('instructionPurchaseForecastSearchView.itemDescription').value;
        var selectCoverage = document.getElementById('instructionPurchaseForecastSearchView.selectCoverage').value;
        var coverage = document.getElementById('instructionPurchaseForecastSearchView.coverage').value;
        var fromYear = document.getElementById('instructionPurchaseForecastSearchView.fromYear').value;
        var toYear = document.getElementById('instructionPurchaseForecastSearchView.toYear').value;
                        
        var errorLen = "";
        
        if(coverage != "" && isNaN(coverage)){
            errorLen = errorLen + '<bean:message key="label.purchases.instructions.forecast.nonumericcoverage"/>\n';
        }         
        if(coverage != "" && (coverage < 0 && coverage > 100) ){
            errorLen = errorLen + '<bean:message key="label.purchases.instructions.forecast.invalidcoverage"/>\n';
        }                 
        if((fromYear != -1 && toYear!=-1) && (fromYear > toYear)){
			errorLen = errorLen + '<bean:message key="label.purchases.instructions.forecast.frombiggerthanto"/>\n';
        } 

		if( errorLen == "" ){
           	return true;
        }else{
           	alert( errorLen );
			return false;
        }
    } 

function submitInstructionPurchase(form, orderField, orderType){
	form.orderField.value = orderField;
	form.orderType.value = orderType;
	form.action = "searchInstructionPurchaseForecastQuery.do";
	if (validSubmit){
		form.submit();
	} else {
		alert('<bean:message key="warning.message.common.processing"/>');
	}
}
</script>
<html:form action="/searchInstructionPurchaseForecastQuery" method="POST" onsubmit="return validate();">
	<html:hidden property="orderField"/>
	<html:hidden property="orderType"/>
	<table align="center" width="99%" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
		<tr>
			<td colspan="13" class="titulocolumna" align="center"><bean:message key="menu.module.corn.instructionpurchase.buy"></bean:message></td>
		</tr>
		<tr>
			<td class="etiqueta" width="3%"><bean:message key="label.purchases.instructions.forecast.customer"/>:</td>
			<td class="etiqueta_campo"  width="5%" >
				<html:text property="instructionPurchaseForecastSearchView.customerDescription" styleId="instructionPurchaseForecastSearchView.customerDescription"  styleClass="campo_texto" size="7" maxlength="10"></html:text>
			</td>
			<td class="etiqueta" width="4%" align="center"><bean:message key="label.purchases.instructions.forecast.item"/>:</td>
			<td class="etiqueta_campo"  width="9%">
				<html:text property="instructionPurchaseForecastSearchView.itemDescription" styleId="instructionPurchaseForecastSearchView.itemDescription" styleClass="campo_texto" size="13"></html:text>
			</td>
			
			<td class="etiqueta" width="6%" align="center"><bean:message key="label.purchases.instructions.forecast.coverage"/>:</td>
			<td class="etiqueta_campo"  width="13%">
				<html:select property="instructionPurchaseForecastSearchView.selectCoverage" styleId="instructionPurchaseForecastSearchView.selectCoverage" styleClass="campo_texto" >
					<option value="<bean:message key="label.selectbalance.major"/>"><bean:message key="label.selectbalance.major"/></option>
					<option value="<bean:message key="label.selectbalance.minor"/>"><bean:message key="label.selectbalance.minor"/></option>
					<option value="<bean:message key="label.selectbalance.equals"/>"><bean:message key="label.selectbalance.equals"/></option>
				</html:select>
			
				<html:text property="instructionPurchaseForecastSearchView.coverage"  styleId="instructionPurchaseForecastSearchView.coverage" styleClass="campo_texto" size="13"  onfocus="this.select();" onkeydown="return (numeric(event, 1) && noPaste(event, this));" onkeyup="extractNumber(this,2,false);"></html:text>
			</td>
			
			<td class="etiqueta" width="4%" align="center"><bean:message key="label.purchases.instructions.forecast.period"/>:</td>
			<td class="etiqueta_campo"  width="10%">
			
				<html:select property="instructionPurchaseForecastSearchView.fromYear" styleId="instructionPurchaseForecastSearchView.fromYear" styleClass="campo_texto" >					
					<html:optionsCollection name="InstructionPurchaseForecastSearchForm" property="periodFrom" value="value" label="label"/>
				</html:select>

			</td>
			<td class="etiqueta" width="5%" align="center"><bean:message key="label.purchases.instructions.forecast.until"/>:</td>
			<td class="etiqueta_campo"  width="10%">
				<html:select property="instructionPurchaseForecastSearchView.toYear" styleId="instructionPurchaseForecastSearchView.toYear" styleClass="campo_texto" >
					<html:optionsCollection name="InstructionPurchaseForecastSearchForm" property="periodFrom" value="value" label="label"/>
				</html:select>			
			</td>			
			<td align="center" class="columnadatoPar"  width="8%">
				<input type="submit" value="<bean:message key="label.common.query"/>" class="boton" id="search" name="search"/>
			</td>		
		</tr>
	</table>
</html:form>
<table align="center" width="99%" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
	<tr>
		<td class="titulocolumna" align="center" width="6%">
			<a href="#>" onclick="return submitInstructionPurchase(document.InstructionPurchaseForecastSearchForm, 1,'<c:choose><c:when test="${previousOrderField == 1 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');" class="ligas">
				<html:link action="/goInstructionPurchaseHeader?filters=news">
					<img alt="<bean:message key="common.add"/> <bean:message key="label.purchases.instructions"/>" src="images/nuevo.gif" border="0">
				</html:link>
				<br/>
				<bean:message key="label.purchases.instructions.forecast.period"/>
			</a>
		</td>
		<td class="titulocolumna" align="center" width="24%">
			<a href="#>" onclick="return submitInstructionPurchase(document.InstructionPurchaseForecastSearchForm, 2,'<c:choose><c:when test="${previousOrderField == 2 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');" class="ligas">
				<bean:message key="label.purchases.instructions.forecast.customer"/>
				<c:choose>
					<c:when test="${previousOrderField == 2 && previousOrderType == 1}">
						<img alt="<bean:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
					</c:when>
					<c:when test="${previousOrderField == 2 && previousOrderType == 0}">
						<img alt="<bean:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
					</c:when>
				</c:choose>
			</a>
		</td>
		<td class="titulocolumna" align="center" width="23%">
			<a href="#>" onclick="return submitInstructionPurchase(document.InstructionPurchaseForecastSearchForm, 3,'<c:choose><c:when test="${previousOrderField == 3 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');" class="ligas">
				<bean:message key="label.purchases.instructions.forecast.item"/>
				<c:choose>
					<c:when test="${previousOrderField == 3 && previousOrderType == 1}">
						<img alt="<bean:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
					</c:when>
					<c:when test="${previousOrderField == 3 && previousOrderType == 0}">
						<img alt="<bean:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
					</c:when>
				</c:choose>
			</a>
		</td>
		<td class="titulocolumna" align="center" width="9%">
			<bean:message key="label.purchases.instructions.forecast.sell"/><br/>
			<bean:message key="label.purchases.instructions.forecast.totalsell"/>
		</td>
		<td class="titulocolumna" align="center" width="8%">
		<bean:message key="label.purchases.instructions.forecast.sell"/><br/>
			<bean:message key="label.purchases.instructions.forecast.closedsell"/>
		</td>
		<td class="titulocolumna" align="center" width="8%">
			<bean:message key="label.purchases.instructions.forecast.sell"/><br/>
			<bean:message key="label.purchases.instructions.forecast.opensell"/>
		</td>
		<td class="titulocolumna" align="center" width="9%" nowrap="true" >
			<bean:message key="label.purchases.instructions.forecast.milling"/><br/>
			<bean:message key="label.purchases.instructions.forecast.sell"/><br/>
			<bean:message key="label.purchases.instructions.forecast.closed"/>
		</td>
		<td class="titulocolumna" align="center" width="6%">
			<bean:message key="label.purchases.instructions.forecast.futurecontracts"/>
		</td>
		<td class="titulocolumna" align="center" width="5%">
			<bean:message key="label.purchases.instructions.forecast.%"/><br/>
			<bean:message key="label.purchases.instructions.forecast.coverage"/>
		</td>
		<td class="titulocolumna" align="center" width="2%">
			&nbsp;
		</td>
	</tr>
<logic:present name="instructionForecastViews">
	<logic:iterate name="instructionForecastViews" id="instrucciones" indexId="int_i">
		<tr class="<%=((int_i.intValue()%2)==0?"columnadatoPar":"columnadatoNon")%>">
			<logic:equal name="instrucciones" property="year" value="0">
				<td colspan="3" align="right" >
					<b><bean:message key="label.purchases.instructions.forecast.totalsell"/></b>
				</td>
			</logic:equal>
			<logic:notEqual name="instrucciones" property="year" value="0">
				<td align="center">
					<a href="#" style="text-decoration: none;" onclick='location.href="goToInstructionForecastDetail.do?periodId=<bean:write name="instrucciones" property="year"/>&customerId=<bean:write name="instrucciones" property="customerId"/>&productId=<bean:write name="instrucciones" property="itemId"/>"' >
						<img 
						alt='<bean:message key="menu.module.corn.instructionpurchase.buy.detail"/>' 
						src="images/application_view_list.png" border="0">
					</a>
					<bean:write name="instrucciones" property="year"/>
				</td>
				<td align="left">
					<bean:write name="instrucciones" property="customerId"/>- <bean:write name="instrucciones" property="customerDescription"/>
				</td>
				<td align="left">
					<bean:write name="instrucciones" property="itemId"/>- <bean:write name="instrucciones" property="itemDescription"/>
				</td>
			</logic:notEqual>
			<td align="right">
				<bean:write name="instrucciones" property="total"/>
			</td>
			<td align="right">
				<bean:write name="instrucciones" property="contracted"/>
			</td>
			<td align="right">
				<bean:write name="instrucciones" property="nonContracted"/>
			</td>
			<td align="right">
				<bean:write name="instrucciones" property="cornContracted"/>
			</td>
			<td align="right">
				<bean:write name="instrucciones" property="instructionFutures"/>
			</td>
			<td align="right">
				<bean:write name="instrucciones" property="coverage"/>
			</td>
			<td>
				
			</td>
		</tr>
	</logic:iterate>
</logic:present>
</table>
<br/>